﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：徐毅
    //
    // 文件名：HospitalRegist.aspx.cs
    // 文件功能描述：医疗机构用户注册
    // 创建标识：xuyi 2009-05-26
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using System.Collections.Generic;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.Model;


namespace HZ.DrugTrade.Web
{
    public partial class HospitalRegist : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetDefaultAreaString();
            }
        }

        #region 获取地区信息
        /// <summary>
        /// 获取地区查询条件 AreaID
        /// </summary>
        /// <returns></returns>
        private string GetAreaID()
        {
            string areaId = "";

            //获取当前用户所在区域
            Area area1 = CurrentAccount.GetCurrentDeployArea();
            areaId = area1.AreaID;

            //优先获取区县，其次城市，再次省份
            if (new Common.ConvertHelper(Request.Form["ddlCountry"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ddlCountry"];
            }
            else
            {
                if (new Common.ConvertHelper(Request.Form["ddlCity"]).String != Constants.ALL_ITEM_VALUE)
                {
                    areaId = Request.Form["ddlCity"];
                }
                else if (new Common.ConvertHelper(Request.Form["ddlProvice"]).String != Constants.ALL_ITEM_VALUE)
                {
                    areaId = Request.Form["ddlProvice"];
                }

            }
            return areaId;
        }
        #endregion

        /// <summary>
        /// 获取默认选中的地区编号串
        /// 供JS函数使用
        /// </summary>
        /// <returns></returns>
        protected string GetDefaultAreaString()
        {
            //默认城市 江苏省 320000
            string defaultProvince = "320000";
            string defaultCity = "";
            //
            string strArea = "";

            //获取当前用户所在区域
            IBLL_Area areaCtrl = Factory.BLL_Area();
            Area area1 = CurrentAccount.GetCurrentDeployArea();
            Area area = areaCtrl.GetArea(area1.AreaID);

            //如果是市级中心机构，则默认选中具体城市
            if (area.FatherAreaID != "0")
            {
                defaultProvince = area.FatherAreaID;
                defaultCity = area.AreaID;
            }
            else
            {
                defaultProvince = area.AreaID;
            }

            //显示默认地区，范围之外的内容禁止选择
            strArea += "," + "\"" + defaultProvince + "\"";
            this.ddlProvice.Enabled = false;
            if (!string.IsNullOrEmpty(defaultCity))
            {
                strArea += "," + "\"" + defaultCity + "\"";
                this.ddlCity.Enabled = false;
            }
            else if (!string.IsNullOrEmpty(Request.Form["ddlCity"]))
            {
                strArea += "," + "\"" + Request.Form["ddlCity"] + "\"";
            }

            if (!string.IsNullOrEmpty(Request.Form["ddlCountry"]))
            {
                strArea += "," + "\"" + Request.Form["ddlCountry"] + "\"";
            }

            return strArea;
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string code = this.txtCode.Text;
            if (CurrentAccount.VerifyValidateCode(code))
            {
                HospitalInfo hif = new HospitalInfo();
                hif.HospitalName = txb_hosName.Text.Trim();
                hif.Address = txb_Addr.Text.Trim();
                hif.Levels = DropDownList1.SelectedItem.Text.Trim();
                hif.AreaID = GetAreaID();
                hif.ContactPerson = txb_HosPerson.Text.Trim();
                hif.TelNo = txb_officeTel.Text.Trim();
                hif.CellNo = txb_officeTel.Text.Trim();
                hif.Email = txb_Email.Text.Trim();
                //if (hif.TelNo == "" || hif.TelNo == null)
                //{
                //    HZ.Web.WebUtil.Alert("请填写电话号码！", this);
                //    return;
                //}
                IBLL_Hospital host = Factory.BLL_Hospital();
                int result = host.RegNewHospital(hif);
                if (result == 1)
                {
                    WebHint.ShowInfo("提交成功！", "JavaScript:{window.close();};");
                }
                else if (result == 2)
                {
                    HZ.Web.WebUtil.Alert("医疗机构信息已经存在！", this);
                }
                else
                {
                    WebHint.ShowError("提交失败！", "");
                }
            }
            else
            {
                this.txtCode.Text = "";
                HZ.Web.WebUtil.Alert("验证码不正确！", this);
            }
        }
    }
}
